import Ships.Miner
import Messaging.Signal
import coords

# **
# *  'Mining' is a state class for the Miner.  The Miner will proceed to mine
# *  gas clouds until storage bay is full.  Mining can also be interupted by
# *  pirates, inwhich the Miner will flee.
# *
# * PUBLIC FEATURES:
# *    // Constructors
# *    def __init__(self)
# *
# *    // Methods
# *    def Enter(self, ship)
# *    def Execute(self, ship)
# *    def Exit(self, ship)
# *    
# *
# *    COLLABORATORS:
# *    Ships.Miner
# *    
# *
# * MODIFIED:
# * @version 1.1, 2007-05-24
# * @author Julian Andreou 5422329
# * @author Gavan Hunter 5422264
# * @author  Simon Iskra 5422361
# * @author  Joel Schmidt 2660660 
# */

class Mining():
    def __init__(self): 
        self.stateString = "Mining"
    """
    #  is the miner prospecting or mining?
    #  if prospecting;
    #  checks if there is a gas cloud to mine within its passiveRadius
    #  if there is it will head there to mine
    #  if not it will continue to wander
    #
    #  if Mining;
    #  increase minerals in storage hold (does gas cloud decrease?)
    #
    #  TRANSITIONS
    #  check if storage bay if full to change sub state to Depositing'
    #  Now check for pirates 
    #  If gas clouds deplete we need to check that cloud still exists
    #  If gas cloud is depleted then go prospecting again"""
    
    def Enter(self, ship):
       pass
    
    def Execute(self, ship): 
          
       currentCoords = ship.getGridCoords()
       #print str(self.ship.getGridCoords())
       newCoords = ship.map.findResources(ship.getGridCoords(), ship.lastCellCoords)
       #print "NewCoords: "+str(newCoords)
       #newCoords = self.map.findResources(self.ship.getGridCoords())
       #if newCoords[0] == currentPosition[0] & newCoords[1] == currentPosition[1]:
       
       """If we don't find higher resources newCoords will be the same as current position"""
       if newCoords == currentCoords:
           if ship.map.getCellResources(currentCoords) <= 0:
               newCoords = ship.map.newRandomCell(ship.getGridCoords())
               #print "searching for minerals..." + str(newCoords)

       if ship.map.getCellResources(currentCoords) > 0:
           ship.minerals += ship.map.mineResources(currentCoords)
           #print "i'm mining! minerals: "+str(ship.minerals)
           
       newCoords = coords.gridToScreen(newCoords)
       #print "newCoords: "+str(newCoords)
       ship.lastCellCoords = currentCoords    
       ship.position = newCoords
    
    def Exit(self, ship):
        pass
    
